/*
*用户相关模块
*/
import request from '@/utils/request'
// import store from '@/store'
// 登录的 API 接口
export const loginAPI = data => {
  return request.post('/v1_0/authorizations', data)
}

// 验证码的API接口
export const codeAPI = mobile => {
  // 只能使用键盘左上角的`
  return request.get(`/v1_0/sms/codes/${mobile}`)
}

// 获取用户信息
export const userinfoAPI = () => {
  return request({
    method: 'GET',
    // url小写
    url: '/v1_0/user'
    // 请求头
    // headers: {
    //   Authorization: `Bearer ${store.state.user.token}`
    // }
  }
  )
}

// 获取用户频道列表信息
export const getUserChannelsAPI = () => {
  return request({
    method: 'GET',
    // url小写
    url: '/v1_0/user/channels'
    // 请求头
    // headers: {
    //   Authorization: `Bearer ${store.state.user.token}`
    // }
  }
  )
}

// 关注文章作者
export const addfollowAPI = (id) => {
  return request({
    method: 'POST',
    // url小写
    url: '/v1_0/user/followings',
    data: {
      target: id
    }
  }
  )
}

// 取消关注文章作者
export const delfollowAPI = (id) => {
  return request({
    method: 'DELETE',
    // url小写
    url: `/v1_0/user/followings/${id}`
    // 请求头
    // headers: {
    //   Authorization: `Bearer ${store.state.user.token}`
    // }
  }
  )
}

// 收藏文章
export const collictAPI = (id) => {
  return request({
    method: 'POST',
    // url小写
    url: '/v1_0/article/collections',
    data: {
      target: id
    }
  }
  )
}

// 取消收藏文章
export const uncollictAPI = (id) => {
  return request({
    method: 'DELETE',
    // url小写
    url: `/v1_0/article/collections/${id}`

  }
  )
}

// 文章点赞
export const likedAPI = (id) => {
  return request({
    method: 'POST',
    // url小写
    url: '/v1_0/article/likings',
    data: {
      target: id
    }
  }
  )
}
// 取消文章点赞
export const unlikedAPI = (id) => {
  return request({
    method: 'DELETE',
    // url小写
    url: `/v1_0/article/likings/${id}`

  }
  )
}
// 获取用户信息
export const getUserProfile = () => {
  return request({
    method: 'GET',
    // url小写
    url: '/v1_0/user/profile'

  }
  )
}
// 修改用户信息
// 修改用户姓名、生日的接口
export const updateUserProfile = (data) => {
  return request({
    method: 'PATCH',
    // url小写
    url: '/v1_0/user/profile',
    data
  }
  )
}
export const updateUserPhoto = (data) => {
  return request({
    method: 'PATCH',
    // url小写
    url: '/v1_0/user/photo',
    data
  }
  )
}
